package com.strawcom.charmring.ui;

import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.strawcom.charmring.BaseActivity;
import com.strawcom.charmring.R;
import com.strawcom.charmring.common.parallax.ParallaxContainer;

public class SplashActivity extends BaseActivity {
	
	private ImageView imgPoint1,imgPoint2,imgPoint3,imgPoint4;

	@Override protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_splash);
		
		ParallaxContainer container = (ParallaxContainer) findViewById(R.id.parallax_container);
		container.setUp(new int[] { R.layout.layout_intro_1, R.layout.layout_intro_2, R.layout.layout_intro_3,R.layout.layout_intro_4 });
		
		final View m = findViewById(R.id.lay_splash_05);
		ObjectAnimator anim3 = ObjectAnimator.ofFloat(m, "scaleX", 1, 1.4f);
		ObjectAnimator anim4 = ObjectAnimator.ofFloat(m, "scaleY", 1, 1.4f);
		ObjectAnimator anim6 = ObjectAnimator.ofFloat(m, "alpha", 1, 0);

		AnimatorSet set = new AnimatorSet();
		set.play(anim3).with(anim4).with(anim6);
		set.setDuration(1200);
		set.setStartDelay(2000);
		set.start();
		set.addListener(new AnimatorListenerAdapter() {
			@Override public void onAnimationEnd(Animator animation) {
				super.onAnimationEnd(animation);
				m.setVisibility(View.GONE);
				m.setAlpha(1);
			}
		});
		
		ViewGroup layPoints = (ViewGroup) findViewById(R.id.lay_points);
		imgPoint1 = (ImageView) layPoints.getChildAt(0);
		imgPoint2 = (ImageView) layPoints.getChildAt(1);
		imgPoint3 = (ImageView) layPoints.getChildAt(2);
		imgPoint4 = (ImageView) layPoints.getChildAt(3);
	}
	
	public void setLightPoint(int position) {
		if(position > 3) position = 3;
		if(position < 0) position = 0;
		
		imgPoint1.setImageResource(R.drawable.bg_splash_point_gray);
		imgPoint2.setImageResource(R.drawable.bg_splash_point_gray);
		imgPoint3.setImageResource(R.drawable.bg_splash_point_gray);
		imgPoint4.setImageResource(R.drawable.bg_splash_point_gray);
		if(position == 0) {
			imgPoint1.setImageResource(R.drawable.bg_splash_point_light);
		} else if(position == 1) {
			imgPoint2.setImageResource(R.drawable.bg_splash_point_light);
		} else if(position == 2) {
			imgPoint3.setImageResource(R.drawable.bg_splash_point_light);
		} else if(position == 3) {
			imgPoint4.setImageResource(R.drawable.bg_splash_point_light);
		}
	}
	
	public void onEnterClick(View view){
		actionStart(FirstActivity.class);
		finish();
	}
}
